$(function() {
$("#searchid").linkbutton({
	 text:'查询',
	 iconCls:'icon-search'
});


	$('#brandlist').datagrid({
		idField : 'id',
		nowrap : false,
		striped : true,
		collapsible : false,
		url : '../brand/search.shtml?auding=0&t='+(new Date().getTime().toString(36)),
        width : 893,
		height : 338,
		frozenColumns : [[{
					field : 'ck',
					title : '选择',
					checkbox : true
				}]],
		columns : [[{
					title : '基本信息',
					colspan : 3
				}, {
					field : 'opt',
					title : '操作',
					width : 200,
					align : 'center',
					rowspan : 2,
					formatter : function(value, rec) {
						if (rec.id == undefined)
							return null;
						else
							return '<span style="color:red"><span onclick=Onmodify("'
									+ rec.id
									+ '")><font style="cursor:pointer">修改</span></font> <span onclick=Ondelete("'
									+ rec.id + '")><font style="cursor:pointer">删除</font></span></span><hr>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<select id="aud_'+rec.sysuserId +'"><option value="1">审核通过</option><option value="2">审核不通过</option></select>&nbsp;<span onclick=OnAutding("'
									+rec.sysuserId+'")><font style="cursor:pointer">审核</font></span></span>';
					}
				}], [{
					field : 'name',
					title : '品牌',
					align:'center',
					width : 150
				},{
					field : 'imgsrc',
					title : '商标',
					align:'center',
					width : 200,
					formatter : function(value, rec) {
						return '<img src="../'+value+'" width="144px" height="45px"/>';
					}
				}	,{
					field : 'auding',
					title : '审核状态',
					align:'center',
					width : 100,
					formatter : function(value, rec) {
						if(value==1)return "审核通过";
					    else if(value==2)return "审核未通过";
						else  return  "<font color='red'>未审核</font>";
					}
				}

		]],
		pagination : true,
		singleSelect:true,
		pageList:[10,20,50,80,100],
		rownumbers : true,
		queryParams : {
			name : name,
			auding : ''
		}
	}

	);
});
function deleteById(id){
   $.ajax({
		url : "../brand/deleteById.shtml?ids=" + id,
		success : function(msg) {
			var obj = eval('(' + msg + ')');
			var result = obj["result"];
			if (result == "3") {
				alert('该品牌被设置了拼购或者广告，禁止删除');
			} else {
				if (!result) {
					alert("删除成功失败");
					return;
				}
				alert("删除成功");
				$('#brandlist').datagrid("reload");
			}
		}
	});
}



function Ondelete(id) {
	if (id == "undefined") {
		alert("此条记录已删除");
		return;
	}
	if (confirm("确定删除此条信息吗?")) {

		deleteById(id);
	}
}
function Onmodify(id) {
	if (id == "undefined") {
		alert("此条记录已删除");
		return;
	}
	window.location.href = "../brand/findMessageById.shtml?id=" + id ;
}
function OnAutding(sysuserId) {
	if (sysuserId == "undefined") {
		alert("此条记录已删除");
		return;
	}
	if (confirm("确定审核此条信息吗?")) {
        var autding=document.getElementById("aud_"+sysuserId).value;
		var url1 = "../brand/updateMessageById.shtml";
						$.ajax({
									url : url1,
									data : "autding="+autding+"&sysuserId="+sysuserId ,
									cache:false,
									success : function(msg) {

										var obj = eval('(' + msg + ')');
				                       var result = obj["result"];
			                          if(!result){
                                            alert("审核失败");
                                           return;
						                     }
						                  alert("审核成功");
										$('#brandlist').datagrid("reload");
									}
								});
	}
}
